package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import javax.xml.crypto.Data;
import java.util.Date;

@Component //将对象交给Spring容器管理 不属于C/S/M
/**
 * 1.自动填充的字段名称
 * 2.自动填充的值
 * 3.MetaObject 固定写法*/
public class MyMetaObjectHandler implements MetaObjectHandler {
    //入库操作时调用
    @Override
    public void insertFill(MetaObject metaObject) {
        //设定时间变量
        Date date = new Date();
        this.setFieldValByName("created", date,metaObject );
        this.setFieldValByName("updated", date,metaObject );

    }
    //更新操作时调用
    @Override
    public void updateFill(MetaObject metaObject) {
        Date date = new Date();
        this.setFieldValByName("updated", date,metaObject );
    }
}
